package com.longjiyi.test;

import java.util.Arrays;
import java.util.HashSet;

public class 最长连续序列 {
    public static void main(String[] args) {
        int[] ints = new int[]{9, 1, 4, 7, 3, -1, 0, 5, 8, -1, 6};
        System.out.println(longestConsecutive(ints));
    }

    public static int longestConsecutive(int[] nums) {
        int max = 0;
        HashSet<Integer> hashSet = new HashSet<Integer>();
        for (int num : nums) {
            hashSet.add(num);
        }
        System.out.println(hashSet);
        for (int num : nums) {
            if (!hashSet.contains(num - 1)) {
                int len = 0;
                while (hashSet.contains(num + len)) {
                    len++;
                    max = Math.max(len, max);
                }
            }
        }


        return max;

    }
}
